<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <link rel="Bookmark" href="../imgs/bai.ico"/>
    <link rel="Shortcut Icon" href="../imgs/bai.ico"/>
    <link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css"/>
    <title>后台管理</title>
    <style type="text/css">
        input[type=button] { margin: 5vh 10px; padding: 10px 0; width: 30%; height: 40px; border: 0; }
    </style>
</head>
<body>
    <!--顶部-->
    <header class="navbar-wrapper"></header>
    <!--左侧菜单-->
    <aside class="Hui-aside">
        <div class="menu_dropdown bk_2" id="leftMenu"></div>
    </aside>
    
    <!--右侧内容框架-->
    <section class="Hui-article-box">
        <nav class="breadcrumb">
            <a href="../index.html" class="maincolor">
                <i class="Hui-iconfont">&#xe67f;</i>
            </a>
            <span class="c-gray en">&gt;</span> 修改密码
        </nav>
        <div class="Hui-article">
        <article class="cl pd-20">
            <div class="form form-horizontal">
                <div class="row cl">
                    <label class="form-label col-xs-4 col-sm-2">
                        <span class="c-red">*</span> 登录账号
                    </label>
                    <div class="formControls col-xs-8 col-sm-9">
                        <input type="text" class="input-text" id="uname" readonly/>
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-xs-4 col-sm-2">
                        <span class="c-red">*</span> 原密码：
                    </label>
                    <div class="formControls col-xs-8 col-sm-9">
                        <input type="text" class="input-text" id="upwd"/>
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-xs-4 col-sm-2">
                        <span class="c-red">*</span> 新密码：
                    </label>
                    <div class="formControls col-xs-8 col-sm-9">
                        <input type="text" class="input-text" id="pwdNew"/>
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-xs-4 col-sm-2">
                        <span class="c-red">*</span> 确认密码：
                    </label>
                    <div class="formControls col-xs-8 col-sm-9">
                        <input type="text" class="input-text" id="pwdNew2"/>
                    </div>
                </div>
                <div class="row cl">
                    <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                        <input class="btn btn-primary radius" type="button" value="&nbsp; 保 存 &nbsp;" onclick="setModify();"/>
                        <input class="btn btn-primary radius" type="button" style="background: orangered;" value="&nbsp; 关 闭 &nbsp;" onclick="toClose();"/>
                    </div>
                </div>
            </div>
        </article>
    </div>
</section>

<!--自定义弹窗-->
<span id="msgPop"></span>
</body>
</html>


<script type="text/javascript" src="../lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="../lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="../static/h-ui/js/H-ui.js"></script>
<script type="text/javascript" src="../static/h-ui.admin/js/H-ui.admin.page.js"></script>
<script type="text/javascript" src="../js/view.js"></script>
<script type="text/javascript">
    var preUrl = getParamByUrl('preUrl');
    console.log(preUrl);
    (function (){
        getInfo();
    })();
    // 用户信息
    function getInfo(){
        var uinfo = getAdminInfo();
        console.log(uinfo);
        $('#uname')[0].value = uinfo.uname;
    }
    // 更新密码
    function setModify(){
        var uinfo = getAdminInfo();
        var formData = {
            id: uinfo.uid,
            upwd: $('#upwd').val(),
            pwdNew: $('#pwdNew').val(),
            pwdNew2: $('#pwdNew2').val(),
        };
        if (formData.upwd == '') {
            msgPop({msg: '密码必须的'}); return
        }
        if (formData.pwdNew == '') {
            msgPop({msg: '新密码必须的'}); return
        }
        if (formData.pwdNew2 == '') {
            msgPop({msg: '确认密码必须的'}); return
        }
        if (formData.pwdNew != formData.pwdNew2) {
            msgPop({msg: '2次新密码不一致'}); return
        }
        $.ajax({
            type: 'post',
            url: apiDomain + 'staff/pwd-set',
            data: formData,
            success: function (res) {
                console.log(res);
                if (res.code < 0) {
                    msgPop({msg: res.msg});
                    return
                }
                msgPop({msg: '成功'});
                setTimeout(function(){
                    // window.location.href = '/admin/login.html';
                    logout();
                }, 500);
            },
            error: function () {
                console.log('网络错误');
            }
        });
    }
    // 关闭
    function toClose(){
        window.location.href = preUrl;
    }
</script>